﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Collections.ObjectModel;
using System.Collections;
using Microsoft.Phone.Shell;

namespace LiveEduWizard
{
    public partial class WeekSelector : PhoneApplicationPage
    {
        public WeekSelector()
        {
            InitializeComponent();
            InitApplicationBar();

            DataContext = App.ViewModel;
        }

        private void InitApplicationBar()
        {
            ApplicationBar = new ApplicationBar();
            ApplicationBar.Mode = ApplicationBarMode.Default;
            ApplicationBar.IsVisible = true;
            ApplicationBar.IsMenuEnabled = true;
            InitApplicationBarButtons();
        }

        private void InitApplicationBarButtons()
        {
            ApplicationBarIconButton backButton = new ApplicationBarIconButton(ThemeHelper.BackButtonImage);
            backButton.Text = ThemeHelper.BackButtonText;
            backButton.Click += new EventHandler(backButton_Click);
            ApplicationBar.Buttons.Add(backButton);
        }

        void backButton_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }

        private void ListBox_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (sender is FrameworkElement && ((FrameworkElement)sender).DataContext is TimetableViewModel)
            {
                App.ViewModel.ActiveTimetable = ((FrameworkElement)sender).DataContext as TimetableViewModel;
                App.ViewModel.SelectAgendaByWeek(App.ViewModel.ActiveTimetable.Week, App.ViewModel.ActiveTimetable.Year);
                NavigationService.GoBack();
            }
        }

        private void Weeks_Loaded(object sender, RoutedEventArgs e)
        {
            Weeks.SelectedItem = App.ViewModel.ActiveTimetable;
            Weeks.ScrollTo(App.ViewModel.ActiveTimetable);

            MainPage.HideProgressIndicator();
        }
    }
}